package cn.kgc.ffzw.day18.homework.chihuolianmeng;

import java.util.Scanner;

/**
 * @author dyy
 * @version 1.0
 * @date 2019/11/24
 * @Description  菜品信息类
 * @since JDK1.8
 */
public class Menu implements InfoList {
    Scanner d=new Scanner(System.in);
    /**
     * 菜单列表基础信息
     */
    private String[] menu={"红烧带鱼", "鱼香肉丝", "时令鲜蔬"};
    private double[] menuprice = {38.0, 20.0, 10.0};
    private int[] menulike={10,9,8};
    private int choice;


    /**
     * 消费者&商家查看方法
     */
    @Override
    public void showmenu() {
        for (int i = 0; i < getMenu().length; i++) {
            System.out.println((i+1)+". "+getMenu()[i]
                    +" "+getMenuprice()[i]+" "+"已赞数："+getMenulike()[i]);
        }
        System.out.println();
    }

    /**
     * 商家修改方法
     */
    @Override
    public void altermenu() {
        System.out.println("请输入要修改的菜品序号：");
        setChoice(d.nextInt());
        if ((getChoice()-1)<getMenu().length) {
            System.out.println(getChoice() + ". " + getMenu()[getChoice() - 1]
                    + " " + getMenuprice()[getChoice() - 1] + " " + getMenulike()[getChoice() - 1]);
            System.out.println("请输入修改后的菜名：");
            getMenu()[getChoice() - 1] = d.next();
            System.out.println("请输入修改后的单价：");
            getMenuprice()[getChoice() - 1] = d.nextDouble();
            System.out.println("修改成功，修改后的菜单信息为：");
            System.out.println(getChoice() + ". " + getMenu()[getChoice() - 1]
                    + " " + getMenuprice()[getChoice() - 1] + " " +"已赞数："+ getMenulike()[getChoice() - 1]);
        }else {
            System.out.println("不在列表范围！");
        }
    }

    /**
     * 增加菜品信息
     */
    @Override
    public void addmenu(){
        System.out.println("请输入要添加的菜品信息条数：");
        setChoice(d.nextInt());
        String[] newMenu=new String[getMenu().length+getChoice()];
        double[] newMenuprice=new double[getMenu().length+getChoice()];
        int[] newMenulike=new int[getMenu().length+getChoice()];
        System.arraycopy(getMenu(),0,newMenu,0,getMenu().length);
        System.arraycopy(getMenuprice(),0,newMenuprice,0,getMenu().length);
        System.arraycopy(getMenulike(),0,newMenulike,0,getMenu().length);
        for (int i = getMenu().length; i < newMenu.length; i++) {
            System.out.println("请输入第"+(i+1)+"条菜品名称：");
            newMenu[i]=d.next();
            System.out.println("请输入相应菜品单价：");
            newMenuprice[i]=d.nextDouble();
            newMenulike[i]=0;
        }
        setMenu(newMenu);
        setMenuprice(newMenuprice);
        setMenulike(newMenulike);
        System.out.println("修改完成，最新菜单如下：");
        this.showmenu();
    };

    /**
     * 删除菜品信息
     */
    @Override
    public void dele(){
        this.showmenu();
        System.out.println("请输入要删除的菜品信息序号：");
        setChoice(d.nextInt());
        for (int i = 0; i < getMenu().length - 1; i++) {
            if (i==(getChoice()-1)){
                getMenu()[i]=getMenu()[i+1];
                getMenuprice()[i]=getMenuprice()[i+1];
                getMenulike()[i]=getMenulike()[i+1];
            }
            System.out.println((i+1)+". "+getMenu()[i]
                    +" "+getMenuprice()[i]+" "+"已赞数："+getMenulike()[i]);
        }
        System.out.println("删除成功！");
    };



    /**
     * 消费者点赞入口
     */
    @Override
    public void like() {
        this.showmenu();
        System.out.println("请输入要点赞的菜品序号：");
        setChoice(d.nextInt());
        getMenulike()[getChoice()-1]+=1;
        System.out.println("点赞成功！");
    }


    public String[] getMenu() {
        return menu;
    }

    public void setMenu(String[] menu) {
        this.menu = menu;
    }

    public double[] getMenuprice() {
        return menuprice;
    }

    public void setMenuprice(double[] menuprice) {
        this.menuprice = menuprice;
    }

    public int[] getMenulike() {
        return menulike;
    }

    public void setMenulike(int[] menulike) {
        this.menulike = menulike;
    }

    public int getChoice() {
        return choice;
    }

    public void setChoice(int choice) {
        this.choice = choice;
    }
}
